package excutors;

import java.util.concurrent.*;

public class TestSche {
    public static void main(String[] args) {
        //创建了一个ScheduledExecutorService 实例
        ScheduledExecutorService executorService=new ScheduledThreadPoolExecutor(1);

        final ScheduledFuture<?> scheduledFuture=executorService.scheduleAtFixedRate(new BeepTask(),10,10
        , TimeUnit.SECONDS);
        Executors.newSingleThreadExecutor();
        Executors.newFixedThreadPool(1);
        executorService.schedule(new Runnable() {
            @Override
            public void run() {
                scheduledFuture.cancel(true);
            }
        },1,TimeUnit.HOURS); //1小时取消任务
    }

    private static class BeepTask implements Runnable{

        @Override
        public void run() {
            System.out.println("beep!...");
        }
    }
}